<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery.js"></script>

<style>
textarea {
	width: 100%;
	overflow: auto;
	word-break: break-all;
}

ul {
	margin: 0;
	padding: 0;
}

li {
	margin: 50px 0px 50px 0px;
	padding: 0;
	list-style-type: none;
}

#listdiv a {
	width: 228px;
	float: left;
	line-height: 18px;
	height: 38px;
	padding: 5px;
	margin: 10px;
	border: 1px dotted #666666;
	background: #EEEEEE;
}
</style>

<script>

function format(txt,compress/*是否为压缩模式*/){/* 格式化JSON源码(对象转换为JSON文本) */  
    var indentChar = '    ';   
    if(/^\s*$/.test(txt)){   
        alert('数据为空,无法格式化! ');   
        return;   
    }   
    try{var data=eval('('+txt+')');}   
    catch(e){   
        alert('数据源语法错误,格式化失败! 错误信息: '+e.description,'err');   
        return;   
    };   
    var draw=[],last=false,This=this,line=compress?'':'\n',nodeCount=0,maxDepth=0;   
       
    var notify=function(name,value,isLast,indent/*缩进*/,formObj){   
        nodeCount++;/*节点计数*/  
        for (var i=0,tab='';i<indent;i++ )tab+=indentChar;/* 缩进HTML */  
        tab=compress?'':tab;/*压缩模式忽略缩进*/  
        maxDepth=++indent;/*缩进递增并记录*/  
        if(value&&value.constructor==Array){/*处理数组*/  
            draw.push(tab+(formObj?('"'+name+'":'):'')+'['+line);/*缩进'[' 然后换行*/  
            for (var i=0;i<value.length;i++)   
                notify(i,value[i],i==value.length-1,indent,false);   
            draw.push(tab+']'+(isLast?line:(','+line)));/*缩进']'换行,若非尾元素则添加逗号*/  
        }else   if(value&&typeof value=='object'){/*处理对象*/  
                draw.push(tab+(formObj?('"'+name+'":'):'')+'{'+line);/*缩进'{' 然后换行*/  
                var len=0,i=0;   
                for(var key in value)len++;   
                for(var key in value)notify(key,value[key],++i==len,indent,true);   
                draw.push(tab+'}'+(isLast?line:(','+line)));/*缩进'}'换行,若非尾元素则添加逗号*/  
            }else{   
                    if(typeof value=='string')value='"'+value+'"';   
                    draw.push(tab+(formObj?('"'+name+'":'):'')+value+(isLast?'':',')+line);   
            };   
    };   
    var isLast=true,indent=0;   
    notify('',data,isLast,indent,false);   
    return draw.join('');   
}  
function farea(sender){
	try{
		var a=format($("#"+sender).val());
		if(a!=undefined && a!=null && a!="")
		$("#"+sender).val(a);
		$("textarea").each(function(){ $(this).css("height",$(this).attr("scrollHeight")); });
	}
	catch(exp){
		alert(exp.message);
	}
}
</script>
</head>
<body>
<form action="testws_debug.php?type=pushmsg&XDEBUG_SESSION_START=ECLIPSE_DBGP" method="post">
<ul>
<li>疏港发送消息</li>
	<li><textarea id="pushmsg" name="pushmsg">{"vhc":"京Aj1568","B_JH_DD":"B_JH_DD","E_JH_DD":"E_JH_DD", "B_ADD":"B_ADD","E_ADD":"E_ADD" ,"CX":"20CP","QTY":1,"SHIP_OVOY":"SHIP_OVOY","TD_NO":"TD_NO","SR_NO":"SR_NO","ITM":1,"PG_ZT":"Y"}</textarea>
	<br />
	<button type="submit">发送消息</button>
	<button type="button" onclick="farea('pushmsg');">格式化</button>
	<br />
	</li>
</ul>
</form>


<form action="testws_debug.php?type=newjsbill&XDEBUG_SESSION_START=ECLIPSE_DBGP" method="post">
<ul>
<li>集港运单</li>
		<li><textarea id="newjsbill" name="newjsbill">{"vhc":"京Aj1568","B_JH_DD":"2016-04-25 05:00","E_JH_DD":"2016-04-27 05:00", "B_ADD":"B_ADD","E_ADD":"E_ADD" ,"CX":"20CP","QTY":1,"SHIP_NO":"SHIP","OVOY":"SHIP_OVOY","TD_NO":"TD_NO","SR_NO":"SR_NO","ITM":1,"PG_ZT":"Y","BOX":[{"SR_NO":"SR_NO1","CX":"CX1", "QTY":"1"  ,"ITM":"1"},{"SR_NO":"SR_NO1","CX":"CX1", "QTY":"1","ITM":"1"}]}</textarea>
<br />
	<button type="submit"">生成运单</button>
	<button type="button" onclick="farea('newjsbill ');">格式化</button>
	<br />
	</li>
	
</form>
<form action="testws_debug.php?type=checkbox&XDEBUG_SESSION_START=ECLIPSE_DBGP" method="post">
<ul>
<li>验箱确认</li>
	<li><textarea id="checkbox"  name="checkbox">{"vhc":"京Aj1568","address":"address","linkman":"","linktel":"13304641234","dt":"2016-04-27"}</textarea>
	<br />
	<button type="submit">验箱</button>
	<button type="button" onclick="farea('checkbox ');">格式化</button>
	<br />
	</li>
</form>
</body>
</html>